package cn.classyex.business.hr.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import cn.classyex.business.hr.domain.Recruitment;
import cn.classyex.business.hr.service.IRecruitmentService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 招聘信息管理Controller
 * 
 * @author yex
 * @date 2021-05-05
 */
@Controller
@RequestMapping("/hr/recruitment")
public class RecruitmentController extends BaseController
{
    private String prefix = "hr/recruitment";

    @Autowired
    private IRecruitmentService recruitmentService;

    @RequiresPermissions("hr:recruitment:view")
    @GetMapping()
    public String recruitment()
    {
        return prefix + "/recruitment";
    }

    /**
     * 查询招聘信息管理列表
     */
    @RequiresPermissions("hr:recruitment:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Recruitment recruitment)
    {
        startPage();
        List<Recruitment> list = recruitmentService.selectRecruitmentList(recruitment);
        return getDataTable(list);
    }

    /**
     * 导出招聘信息管理列表
     */
    @RequiresPermissions("hr:recruitment:export")
    @Log(title = "招聘信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Recruitment recruitment)
    {
        List<Recruitment> list = recruitmentService.selectRecruitmentList(recruitment);
        ExcelUtil<Recruitment> util = new ExcelUtil<Recruitment>(Recruitment.class);
        return util.exportExcel(list, "招聘信息管理数据");
    }

    /**
     * 新增招聘信息管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存招聘信息管理
     */
    @RequiresPermissions("hr:recruitment:add")
    @Log(title = "招聘信息管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Recruitment recruitment)
    {
        return toAjax(recruitmentService.insertRecruitment(recruitment));
    }

    /**
     * 修改招聘信息管理
     */
    @GetMapping("/edit/{recruitmentId}")
    public String edit(@PathVariable("recruitmentId") Long recruitmentId, ModelMap mmap)
    {
        Recruitment recruitment = recruitmentService.selectRecruitmentById(recruitmentId);
        mmap.put("recruitment", recruitment);
        return prefix + "/edit";
    }

    /**
     * 修改保存招聘信息管理
     */
    @RequiresPermissions("hr:recruitment:edit")
    @Log(title = "招聘信息管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Recruitment recruitment)
    {
        return toAjax(recruitmentService.updateRecruitment(recruitment));
    }

    /**
     * 删除招聘信息管理
     */
    @RequiresPermissions("hr:recruitment:remove")
    @Log(title = "招聘信息管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(recruitmentService.deleteRecruitmentByIds(ids));
    }
}
